package com.ljf.controller;

import com.ljf.annotation.HasPermission;
import com.ljf.dto.DeptSaveDto;
import com.ljf.dto.QueryDept;
import com.ljf.service.DeptService;
import com.ljf.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Validated
@RequestMapping("/personnel_management/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

    @GetMapping("/list")
    public Result listBydto(QueryDept queryDept){
        return Result.success(deptService.listBydto(queryDept));
    }

    /**
     * 禁用
     * @param id
     * @return
     */
    @HasPermission("personnel_management:dept:deactivate")
    @PostMapping("/deactivate")
    public Result deactivate(Long id){
        deptService.forbiddenDept(id);
        return Result.success();
    }
    @HasPermission("personnel_management:dept:save")
    @PostMapping("/save")
    public Result saveDept(DeptSaveDto saveDto){
        deptService.saveDept(saveDto);
        return Result.success();
    }

    @HasPermission("personnel_management:dept:update")
    @PostMapping("/update")
    public Result update(DeptSaveDto deptSaveDto){
        deptService.updateDept(deptSaveDto);
        return Result.success();
    }
}
